/*
 * Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
 *
 * Author:     zhukewei <zhukewei@uniontech.com>
 *
 * Maintainer: zhukewei <zhukewei@uniontech.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef YLOGGER_H
#define YLOGGER_H
#include <stdarg.h>
#include <string>
//debug
#define YDEBUG(fmt, ...) \
do \
{ \
	YLogger::instance().debug(__FILE__, __LINE__, __FUNCTION__,fmt, ##__VA_ARGS__);\
}while(0)

//info
#define YINFO(fmt, ...) \
do \
{ \
	YLogger::instance().debug(__FILE__, __LINE__, __FUNCTION__,fmt, ##__VA_ARGS__);\
}while(0)

//warn
#define YWARN(fmt, ...) \
do \
{ \
	YLogger::instance().debug(__FILE__, __LINE__, __FUNCTION__,fmt, ##__VA_ARGS__);\
}while(0)

//error
#define YERROR(fmt, ...) \
do \
{ \
	YLogger::instance().debug(__FILE__, __LINE__, __FUNCTION__,fmt, ##__VA_ARGS__);\
}while(0)

//fatal
#define YFATAL(fmt, ...) \
do \
{ \
	YLogger::instance().debug(__FILE__, __LINE__, __FUNCTION__,fmt, ##__VA_ARGS__);\
}while(0)
	
	
class YLogger
{
public:
	static YLogger& instance(void);
	static void init(const char* name);
	static void debug(const char* file, const int line, const char* fun, const char* fmt, ...);
	static void info(const char* file, const int line, const char* fun, const char* fmt, ...);
	static void warn(const char* file, const int line, const char* fun, const char* fmt, ...);
	static void error(const char* file, const int line, const char* fun, const char* fmt, ...);
	static void fatal(const char* file, const int line, const char* fun, const char* fmt, ...);
private:
	static std::string common(const char* fmt, va_list vList);
	YLogger();
	~YLogger();
};
	
#endif








